/**
 * Copyright (c) 2014, 2016 itemis AG (http://www.itemis.eu) and others.
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0.
 * 
 * SPDX-License-Identifier: EPL-2.0
 */
package org.eclipse.xtend.core.tests.compiler;

import org.eclipse.xtend2.lib.StringConcatenation;
import org.junit.Ignore;
import org.junit.Test;

/**
 * @author Sebastian Zarnekow - Initial contribution and API
 */
@SuppressWarnings("all")
public class CompilerBug422864Test extends AbstractXtendCompilerTest {
  @Test
  public void testBug422864_00() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class C {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def Pair<Pair<Integer, Double>, String> test(L<Pair<Pair<Integer, Double>, String>> l) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return l.maximum(O.doubleO.c[it| it.key.value])");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.append("class L<A> {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("new(A a) {}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def A maximum(O<A> o) {}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.append("class O<A> {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("static def O<Double> doubleO() {}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def <B> O<B> c((B)=>A f) {}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function1;");
    _builder_1.newLine();
    _builder_1.append("import org.eclipse.xtext.xbase.lib.Pair;");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("@SuppressWarnings(\"all\")");
    _builder_1.newLine();
    _builder_1.append("public class C {");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public Pair<Pair<Integer, Double>, String> test(final L<Pair<Pair<Integer, Double>, String>> l) {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("final Function1<Pair<Pair<Integer, Double>, String>, Double> _function = new Function1<Pair<Pair<Integer, Double>, String>, Double>() {");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("public Double apply(final Pair<Pair<Integer, Double>, String> it) {");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("return it.getKey().getValue();");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("};");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("return l.maximum(O.doubleO().<Pair<Pair<Integer, Double>, String>>c(_function));");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    this.assertCompilesTo(_builder, _builder_1);
  }

  @Ignore
  @Test
  public void testBug422864_01() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class C {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def Pair<Pair<Integer, Double>, String> test(L<Pair<Pair<Integer, Double>, String>> l) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return l.maximum(println(O.doubleO.c[it| it.key.value]))");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.append("class L<A> {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("new(A a) {}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def A maximum(O<A> o) {}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.append("class O<A> {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("static def O<Double> doubleO() {}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def <B> O<B> c((B)=>A f) {}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("import org.eclipse.xtext.xbase.lib.Functions.Function1;");
    _builder_1.newLine();
    _builder_1.append("import org.eclipse.xtext.xbase.lib.InputOutput;");
    _builder_1.newLine();
    _builder_1.append("import org.eclipse.xtext.xbase.lib.Pair;");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("@SuppressWarnings(\"all\")");
    _builder_1.newLine();
    _builder_1.append("public class C {");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public Pair<Pair<Integer, Double>, String> test(final L<Pair<Pair<Integer, Double>, String>> l) {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("O<Double> _doubleO = O.doubleO();");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("final Function1<Pair<Pair<Integer, Double>, String>, Double> _function = new Function1<Pair<Pair<Integer, Double>, String>, Double>() {");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("public Double apply(final Pair<Pair<Integer, Double>, String> it) {");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("Pair<Integer, Double> _key = it.getKey();");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("return _key.getValue();");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("};");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("O<Pair<Pair<Integer, Double>, String>> _c = _doubleO.<Pair<Pair<Integer, Double>, String>>c(_function);");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("O<Pair<Pair<Integer, Double>, String>> _println = InputOutput.<O<Pair<Pair<Integer, Double>, String>>>println(_c);");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("return l.maximum(_println);");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    this.assertCompilesTo(_builder, _builder_1);
  }

  @Ignore
  @Test
  public void testBug422864_02() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class C {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def Pair<Pair<Integer, Double>, String> test(L<Pair<Pair<Integer, Double>, String>> l) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return l.maximum(O.doubleO.c[it| it.key.value].or(null))");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("static def <A> O<A> or(O<A> one, O<A> two) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("null");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.append("class L<A> {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("new(A a) {}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def A maximum(O<A> o) {}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.append("class O<A> {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("static def O<Double> doubleO() {}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def <B> O<B> c((B)=>A f) {}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("import java.util.Arrays;");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("@SuppressWarnings(\"all\")");
    _builder_1.newLine();
    _builder_1.append("public class C {");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("protected Object _m(final A a) {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("return null;");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("protected Object _m(final B b) {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("return null;");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public Object m(final A a) {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("if (a instanceof B) {");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("return _m((B)a);");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("} else if (a != null) {");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("return _m(a);");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("} else {");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("throw new IllegalArgumentException(\"Unhandled parameter types: \" +");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("Arrays.<Object>asList(a).toString());");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    this.assertCompilesTo(_builder, _builder_1);
  }

  @Ignore
  @Test
  public void testBug422864_03() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class C {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def Pair<Pair<Integer, Double>, String> test(L<Pair<Pair<Integer, Double>, String>> l) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return l.maximum(or(O.doubleO.c[it| it.key.value], null))");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("static def <B> O<B> or(O<B> one, O<B> two) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("null");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.append("class L<A> {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("new(A a) {}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def A maximum(O<A> o) {}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.append("class O<A> {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("static def O<Double> doubleO() {}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def <R> O<R> c((R)=>A f) {}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("import java.util.Arrays;");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("@SuppressWarnings(\"all\")");
    _builder_1.newLine();
    _builder_1.append("public class C {");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("protected Object _m(final A a) {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("return null;");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("protected Object _m(final B b) {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("return null;");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public Object m(final A a) {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("if (a instanceof B) {");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("return _m((B)a);");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("} else if (a != null) {");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("return _m(a);");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("} else {");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("throw new IllegalArgumentException(\"Unhandled parameter types: \" +");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("Arrays.<Object>asList(a).toString());");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    this.assertCompilesTo(_builder, _builder_1);
  }

  @Ignore
  @Test
  public void testBug422864_04() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class C {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def Pair<Pair<Integer, Double>, String> test(L<Pair<Pair<Integer, Double>, String>> l) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("return l.maximum(O.doubleO.c[it| it.key.value].or(null))");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def <A> A maximum(Iterable<A> iterable) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("} ");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("static def <A> O<A> or(O<A> one, O<A> two) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("null");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.append("class L<A> {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("new(A a) {}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def A maximum(O<A> o) {}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.append("class O<A> {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("static def O<Double> doubleO() {}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def <B> O<B> c((B)=>A f) {}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("import java.util.Arrays;");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("@SuppressWarnings(\"all\")");
    _builder_1.newLine();
    _builder_1.append("public class C {");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("protected Object _m(final A a) {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("return null;");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("protected Object _m(final B b) {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("return null;");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public Object m(final A a) {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("if (a instanceof B) {");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("return _m((B)a);");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("} else if (a != null) {");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("return _m(a);");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("} else {");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("throw new IllegalArgumentException(\"Unhandled parameter types: \" +");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("Arrays.<Object>asList(a).toString());");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    this.assertCompilesTo(_builder, _builder_1);
  }

  @Ignore
  @Test
  public void testBug422864_05() {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class Bug3 {");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def void test() {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("val p = 1 -> 1.0 -> \"a\"");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("val l = new L(p)");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("val l2 = l.maximum(O.doubleO.c[key.value].or(O.doubleO.c[key.value]))");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("l2.toString");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def <A> A maximum(Iterable<A> iterable) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("} ");
    _builder.newLine();
    _builder.append("\t");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("static def <A> O<A> or(O<A> one, O<A> two) {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("null");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.append("class L<A> {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("new(A a) {}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def A maximum(O<A> o) {}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.append("class O<A> {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("static def O<Double> doubleO() {}");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("def <B> O<B> c((B)=>A f) {}");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("import java.util.Arrays;");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("@SuppressWarnings(\"all\")");
    _builder_1.newLine();
    _builder_1.append("public class C {");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("protected Object _m(final A a) {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("return null;");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("protected Object _m(final B b) {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("return null;");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("public Object m(final A a) {");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("if (a instanceof B) {");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("return _m((B)a);");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("} else if (a != null) {");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("return _m(a);");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("} else {");
    _builder_1.newLine();
    _builder_1.append("      ");
    _builder_1.append("throw new IllegalArgumentException(\"Unhandled parameter types: \" +");
    _builder_1.newLine();
    _builder_1.append("        ");
    _builder_1.append("Arrays.<Object>asList(a).toString());");
    _builder_1.newLine();
    _builder_1.append("    ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("  ");
    _builder_1.append("}");
    _builder_1.newLine();
    _builder_1.append("}");
    _builder_1.newLine();
    this.assertCompilesTo(_builder, _builder_1);
  }
}
